package com.example.module_home.adapter

import android.widget.BaseAdapter
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.example.module_home.R
import com.example.module_home.entity.DeviceEntityItem

class DevicesListAdapter : BaseQuickAdapter< DeviceEntityItem , BaseViewHolder>(R.layout.device_item) {
    override fun convert(holder: BaseViewHolder, item: DeviceEntityItem) {
        holder.getView<TextView>(R.id.devices_name).text = item.deviceName
        holder.getView<TextView>(R.id.devices_status).text = item.status
        holder.getView<TextView>(R.id.devices_type).text = item.deviceType
        holder.getView<TextView>(R.id.devices_error).text = "${item.failureRate*100}%"
        holder.getView<TextView>(R.id.devices_location).text = item.installationLocation

        if (item.status == "故障"){
            holder.getView<TextView>(R.id.devices_status).setBackgroundResource(R.drawable.devices_error_bg)
        }else{
            holder.getView<TextView>(R.id.devices_status).setBackgroundResource(R.drawable.devices_noraml_bg)
        }
    }
}